﻿namespace ePubReader
{
    using System.Collections.Generic;
    using System.Linq;

    public class Guide : IEnumerable<Reference>
    {
        Dictionary<string, Reference> references;

        public Guide()
        {
            references = new Dictionary<string, Reference>();
        }

        public Reference this[string type]
        {
            get
            {
                if (this.references.ContainsKey(type))
                {
                    return this.references[type];
                }

                return default(Reference);
            }
            set
            {
                if (this.references.ContainsKey(type))
                {
                    this.references[type] = value;
                }
                else
                {
                    this.references.Add(type, value);
                }
            }
        }

        public bool Contains(string type)
        {
            return this.references.ContainsKey(type);
        }

        public IEnumerator<Reference> GetEnumerator()
        {
            return this.references.Select(x => x.Value).GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }
    }
}
